package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.entity.Employee;
import com.sky.enumeration.OperationType;
import com.sky.result.PageResult;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {

    // 分页查询
    @Select({"<script>",
            "select * from category",
            "<where>",
            "<if test='name != null and name != \"\"'>",
            "and name like concat('%',#{name},'%')",
            "</if>",
            "<if test='type != null'>",
            "and type = #{type}",
            "</if>",
            "</where>",
            "order by sort asc , create_time desc",
            "</script>"})
    Page<Category> pageQuery(CategoryPageQueryDTO categoryPageQueryDTO);


    //
    @Update("update category set status = #{status} where id = #{id}")
    //@AutoFill(value = OperationType.UPDATE)
    void update(Category category);

    // 新增
    @Insert("insert into category (type, name, sort, create_time, update_time, create_user, update_user) " +
            "values " +
            "(#{type}, #{name}, #{sort}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    //@AutoFill(value = OperationType.INSERT)
    void insert(Category category);

    @Delete("delete from category where id = #{id}")
    void deleteById(Long id);

    @Select("select * from category where id = #{id}")
    Category getById(Long id);


    @Update("update category set type = #{type}, name = #{name}, sort = #{sort}, update_time = #{updateTime}, update_user = #{updateUser} where id = #{id}")
  //  @AutoFill(value = OperationType.UPDATE)
    void updatexx(Category category);

    // 根据类型查询,如果type为空全部查询，否则，部分查询
//    @Select({"<script>",
//            "select * from category",
//            "<where>",
//            "<if test='type != null'>",
//            "and type = #{type}",
//            "</if>",
//            "</where>",
//            "order by sort asc , create_time desc",
//            "</script>"})
    List<Category> list(Integer type);
}
